#include <iostream>
using namespace std;

int tmp[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}

void BFS(int x, int y)
{
    if(x>=0 && x<4 && y>=0 && y<3)
    {
        cout << x << " " << y << endl;
        for(int i=0; i<4; ++i)
            if(x+tmp[i][0]>=0 && x+tmp[i][0]<4 && y+tmp[i][1]>=0 && y+tmp[i][1]<=3)
                BFS(x+tmp[i][0], y+tmp[i][1]);
    }
}


int main()
{
   int arr[4][3] = {{1,2,3}, {4,5,6}, {7,8,9}, {11,12,13}};
   int vis[4][3] = 0;
   BFS(0, 0);
   return 0;
}
